package chepter04.db4_3;

import java.util.Scanner;

// 抽象类
abstract class Soundable{
    public abstract void makeSound();
    public abstract void adjustVolume(int volume);
}
class Radio extends Soundable{

    @Override
    public void makeSound() {
        System.out.println("收音机发出声音");
    }

    @Override
    public void adjustVolume(int volume) {
        System.out.println("调整收音机音量为："+ volume);
    }
}
class Walkman extends Soundable{

    @Override
    public void makeSound() {
        System.out.println("随身听发出声音");
    }

    @Override
    public void adjustVolume(int volume) {
        System.out.println("调整随身听音量为："+ volume);
    }
}
class MobilePhone extends  Soundable{
    @Override
    public void makeSound() {
        System.out.println("手机发出声音");
    }
    public void adjustVolume(int volume){
        System.out.println("调整手机音量为："+ volume);
    }
}
public class Application{
    public static void main(String[] args) {
        Soundable soundable = null;
        Scanner scanner = new Scanner(System.in);
        System.out.println("请荀泽设备(1.收音机2.随身听3.手机) :");
        int choice = scanner.nextInt();
        switch (choice){
            case 1:
                soundable = new Radio();
                break;
            case 2:
                soundable = new Walkman();
                break;
            case 3:
                soundable = new MobilePhone();
                break;
            default:
                System.out.println("无效选择");
                return;
        }
        soundable.makeSound();
        System.out.println("请输入音量");
        int volume = scanner.nextInt();
        soundable.adjustVolume(volume);
    }

}
